//
// Created by xili on 2024/8/5 10:02.
// Go big or go home.
//
#include <iostream>
#include <algorithm>

using namespace std;

class Solution {
public:
    string reverseWords(string s) {
        int n = s.size();
        int i = 0, j = 1;
        for (; j < n; j++) {
            if (s[j] == ' ') {
                reverse(s.begin() + i, s.begin() + j);
                i = j + 1;
            }
        }
        reverse(s.begin() + i, s.begin() + j);
        return s;
    }
};